import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
// 适配像素
import 'package:in_out_goods_manage/utiles/adapation.dart';
// 商品卡片
import 'package:in_out_goods_manage/components/good_card.dart';
// 商品信息
import 'package:in_out_goods_manage/model/goods_manage.dart';
import 'package:provider/provider.dart';
// appbar搜索框
import 'package:in_out_goods_manage/components/search_appbar.dart';

class GoodsManagePage extends HookWidget {
  const GoodsManagePage({super.key});

  @override
  Widget build(BuildContext context) {
    var goodsManageModel = Provider.of<GoodsManageModel>(context);
    final goodsList = useState<List<GoodsItem>>(goodsManageModel.goodsList);

    ///出库提交
    goodsSubmit(val) {
      goodsManageModel.reduceGoods(val);
      // goodsList.value = goodsManageModel.goodsList;
    }

    return Scaffold(
      appBar: AppBar(
        title: const Text('merchandiseManagement'),
        actions: [
          IconButton(
              onPressed: () => {
                    Navigator.pushNamed(context, '/goodAddPage',
                        arguments: {'goodsNo': ''})
                  },
              icon: const Icon(
                Icons.add,
                color: Color(0xFF3084FC),
              ))
        ],
      ),
      body: SizedBox(
        width: double.infinity,
        child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
          SizedBox(height: AdaptSize.px(16.5)),
          SearchAppBar(
            hintLabel: 'enterTheNumberNameBrand',
            width: AdaptSize.px(345),
            height: AdaptSize.px(40),
            onChanged: (value) {
              List<GoodsItem> filterList = goodsManageModel.findGoods(value);
              debugPrint(filterList.toString());
              goodsList.value = filterList;
            },
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.all(20.0),
              child: ListView(
                children: goodsList.value
                    .map((e) => GoodsCard(
                        goodsBrand: e.goodsBrand,
                        goodsName: e.goodsName,
                        goodsNo: e.goodsNo,
                        goodsPrice: '￥${e.goodsPrice}',
                        btnText: 'outboundShipments',
                        onPressed: goodsSubmit))
                    .toList(),
              ),
            ),
          )
        ]),
      ),
    );
  }
}
